home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue34
/
construc
/
BERT.INC
< prev
next >
Wrap
Text File
|
1998-05-11
|
10KB
|
282 lines
procedure GenerateContents(var Str: String);
const
IniFile = '.\report.ini';
procedure DataSetTable(DataSet: TDataSet; NewRec: Boolean);
{ NEW RECORD - Actions: POST, CANCEL }
{ BROWSE RECORD - Actions: FIRST, PREV, NEXT, LAST, INSERT, DELETE, REFRESH }
const
Int: Array[1..9] of Char = '123456789';
var
i,j,col,items: Integer;
option: ShortString;
begin
{$IFDEF DEBUG}
Str := Str + '<P>';
Str := Str + 'Debug Action: <INPUT TYPE=TEXT NAME=Action>'#13#10;
Str := Str + '<P>';
{$ENDIF}
if NewRec then
begin
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Post>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Cancel>'#13#10
end
else
begin
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=First>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Prev>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Next>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Last>'#13#10;
Str := Str + ' '#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Insert>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Delete>'#13#10;
Str := Str + ' '#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Find>'#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Query>'#13#10;
Str := Str + ' '#13#10;
Str := Str + '<INPUT TYPE=SUBMIT NAME=Action VALUE=Refresh>'#13#10;
end;
Str := Str + '<INPUT TYPE=RESET VALUE=Reset>'#13#10;
Str := Str + '<P>'#13#10;
with DataSet do
begin
if NewRec then
Str := Str + '<INPUT TYPE=HIDDEN NAME="'+Fields[0].FieldName+
'" VALUE="-1">'#13#10
else
Str := Str + '<INPUT TYPE=HIDDEN NAME="'+Fields[0].FieldName+
'" VALUE="'+Fields[0].AsString+'">'#13#10;
Str := Str + '<TABLE BGCOLOR=BBBBBB BORDER><TR>'#13#10;
col := 0;
with TIniFile.Create(IniFile) do
try
for i:=1 to FieldCount-1 do { first field was hidden }
begin
if Fields[i].DataType = ftMemo then
begin
Str := Str + '</TR><TR><TD COLSPAN=3>';
col := 3;
end
else
if Fields[i].Size > 99 then
begin
Inc(col,2);
if col > 3 then
begin
Str := Str + '</TR><TR>';
col := 2
end;
Str := Str + '<TD COLSPAN=2>'
end
else
begin
Inc(col);
if col > 3 then
begin
Str := Str + '</TR>'#13#10'<TR>';
col := 1
end;
Str := Str + '<TD>'
end;
Str := Str + '<B>'+ReadString(Fields[i].FieldName,'Name',Fields[i].FieldName)+'</B><BR>';
items := ReadInteger(Fields[i].FieldName,'Items',0);
if items = 0 then
begin
if Fields[i].DataType = ftMemo then
begin
Str := Str + '<TEXTAREA NAME="'+Fields[i].FieldName+'" ROWS=6 COLS=72>';
if not NewRec then
Str := Str + Fields[i].AsString;
Str := Str + '</TEXTAREA>'
end
else
begin
if Fields[i].Size > 99 then
Str := Str + '<INPUT TYPE=text NAME="'+Fields[i].FieldName+'" SIZE=64'
else
if Fields[i].Size = 0 then
Str := Str + '<INPUT TYPE=text NAME="'+Fields[i].FieldName+'" SIZE=30'
else
Str := Str + '<INPUT TYPE=text NAME="'+Fields[i].FieldName+'" SIZE='+IntToStr(Fields[i].Size);
if not NewRec then
Str := Str + ' VALUE="'+Fields[i].AsString+'"';
Str := Str + '>'
end
end
else
begin
Str := Str + '<SELECT NAME="'+Fields[i].FieldName+'">';
for j:=1 to items do
begin
option := ReadString(Fields[i].FieldName,'Item'+Int[j],Int[j]);
if (not NewRec) and (option = Fields[i].AsString) then { selected }
Str := Str + '<OPTION SELECTED VALUE="'+option+'">'+option+' '
else
Str := Str + '<OPTION VALUE="'+option+'">'+option+' '
end;
Str := Str + '</SELECT>'
end;
Str := Str + '</TD>'
end;
Str := Str + '</TR>'#13#10
finally
Str := Str + '</TABLE>'#13#10;
Free
end
end
end;
const
_DatabaseName = ''; { no alias: current directory }
_TableName = 'report.db';
Action: String[7] = '';
var
Table: TTable;
Session: TSession; { IMPORTANT }
Report,i: Integer; { key field }
NoChange: Boolean;
begin
Str := '';
Action := '';
ShortDateFormat := 'DD/MM/YYYY';
GetDir(0,Str);
if IOResult <> 0 then { skip };
Str := Str + '<HTML>'#13#10;
with TIniFile.Create(IniFile) do
try
Str := Str + '<HEAD>'#13#10;
Str := Str + '<TITLE>'+ReadString(_TableName,'Name','')+'</TITLE>'#13#10;
Str := Str + '</HEAD>'#13#10;
Str := Str + '<BODY BGCOLOR=AAAAAA>'#13#10;
Str := Str + '<CENTER>'#13#10;
Str := Str + '<H1>';
Str := Str + '<IMG SRC="'+ReadString(_TableName,'Bitmap','')+'">';
Str := Str + ReadString(_TableName,'Name','');
Str := Str + '</H1>'#13#10;
Str := Str + '<FORM METHOD=POST ACTION="'+ReadString(_TableName,'Action','')+'">'#13#10
finally
Free
end;
// IMPORTANT
Session := TSession.Create(nil);
Session.AutosessionName := True;
Session.Active := True;
// IMPORTANT
Table := TTable.Create(nil);
Table.SessionName := Session.SessionName;
with Table do
try
Active := False;
TableType := ttParadox;
{ DatabaseName := _DatabaseName; }
TableName := _TableName;
Open;
First;
{ locate current record }
Report := ValueAsInteger('Report');
if Report > 0 then FindKey([Report])
else First;
{ update record if data has changed }
NoChange := True; { assume no change }
if (Value('_'+Fields[0].FieldName) <> '') and { old data is stored }
(ValueAsInteger(Fields[0].FieldName) <> -1) then
begin
NoChange := True; { assume no change }
for i:=0 to FieldCount-1 do
NoChange := NoChange AND
(Value('_'+Fields[i].FieldName) = Value(Fields[i].FieldName));
if not NoChange then { update record }
begin
{ check if data in table is still the same }
NoChange := True;
for i:=0 to FieldCount-1 do
NoChange := NoChange AND
(Value('_'+Fields[i].FieldName) = Fields[i].AsString);
if not NoChange then { table changed!! }
begin
Str := Str + '<B>Error: value of record changed before your update was made!</B>';
Action := 'Refresh' { force refresh }
end
else { go ahead! }
begin
Str := Str + '<FONT SIZE=2>Note: ';
Edit; { set Table in Edit-mode }
for i:=0 to FieldCount-1 do
begin
if (Value('_'+Fields[i].FieldName) <> Value(Fields[i].FieldName)) then
begin
{$IFDEF DEBUG}
Str := Str + IntToStr(i)+' ['+Value('_'+Fields[i].FieldName)+']-{'+Value(Fields[i].FieldName)+'} ';
{$ENDIF}
Fields[i].AsString := Value(Fields[i].FieldName) { new }
end
end;
Post { Post data in Table };
Str := Str + ' previous record updated in table</FONT><P>'#13#10
end
end
end;
{ determine action }
if Action = '' then
Action := Value('Action');
if Action = '' then Action := 'First';
{ perform action }
if Action = 'First' then First
else
if Action = 'Next' then Next
else
if Action = 'Prev' then Prior
else
if Action = 'Last' then Last
else
if (Action = 'Find') or (Action = 'Query') then
begin
// TODO: special query CGI-Form
end
else
if Action = 'Delete' then Delete
else
if Action = 'Insert' then { skip }
else
if Action = 'Post' then { insert record }
begin
First;
Report := 0;
while not Eof do
begin
if Fields[0].AsInteger > Report then Report := Fields[0].AsInteger;
Next
end;
Inc(Report);
Insert;
Fields[0].AsInteger := Report;
for i:=1 to FieldCount-1 do
Fields[i].AsString := Value(Fields[i].FieldName);
Post
end
else
if Action = 'Cancel' then { cancel }
else
{ Refresh };
Str := Str + '<P><B>' + Action + '</B><P>';
for i:=0 to FieldCount-1 do
Str := Str + '<INPUT TYPE=HIDDEN NAME="_'+Fields[i].FieldName+
'" VALUE="'+Fields[i].AsString+'">'#13#10;
Str := Str + Fields[0].AsString+' - '+IntToStr(RecNo)+
'/'+IntToStr(RecordCount)+' '#13#10;
{ generate HTML CGI-Form with fields }
DataSetTable(Table,Action = 'Insert');
Close
finally
Str := Str + '</FORM>'#13#10;
Str := Str + '</BODY>'#13#10;
Str := Str + '</HTML>'#13#10;
Free
end;
// IMPORTANT
Session.Free;
Session := nil;
// IMPORTANT
Table := nil
end;